<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>采购计划</title>
<link rel="stylesheet" type="text/css"
	href="<c:url value="/css/themes/default/easyui.css"/>">
<link rel="stylesheet" type="text/css"
	href="<c:url value="/css/themes/icon.css"/>">

<script type="text/javascript" src="<c:url value="/js/jquery.min.js"/>"></script>
<script type="text/javascript"
	src="<c:url value="/js/jquery.easyui.min.js"/>"></script>
<script type="text/javascript"
	src="<c:url value="/js/easyui-lang-zh_CN.js"/>"></script>
</head>
<body>
	<script type="text/javascript">
		$(function() {
			//打开采购计划窗口，远程加载数据
			$("#lfq-purchasePlan-add1").linkbutton({
				onClick : function() {
					$('#lfq-purchasePlan-win-add1').window({
						'title' : "制定采购计划",
						'href' : "LfqCaigjh"
					});
					$("#lfq-purchasePlan-win-add1").window("open");
				}
			});

			//打开自定采购计划窗口，远程加载数据
			$("#lfq-purchasePlan-add2").linkbutton({
				onClick : function() {
					$("#lfq-xitongpurchasePlan-win-add2").window({
						'title' : "制定采购计划",
						'href' : "LfqZiDingcgjh"
					});
					$("#lfq-xitongpurchasePlan-win-add2").window("open");
				}
			});

			//刷新
			$("#lfq-purchasePlan-reload1").linkbutton({
				onClick : function() {
					$("#lfq-tb-purchasePlan").datagrid({
						url : 'selectPurchaseplanYaopAll',
						method : 'post'
					});
					$("#lfq-purchasePlan-search1").searchbox("setValue","");
				}
			});

			//根据采购编号查找采购计划
			$('#lfq-purchasePlan-search1').searchbox({
				searcher : function(value, name) {
					if (value == null || value.length == 0) {

					} else {
						$("#lfq-tb-purchasePlan").datagrid({
							url : 'selectPurchaseplanYaop',
							method : 'post',
							queryParams : {
								cgjhNo : value
							}
						});
					}
				}
			});

			//改变行内样式
			$('#lfq-tb-purchasePlan').datagrid({
				rowStyler : function(index, row) {
					var endtime = new Date();
					var year = endtime.getYear() + 1900;
					var mouth = endtime.getMonth() + 1;
					if (mouth < 10) {
						mouth = "0" + mouth;
					}
					var day = endtime.getDate();
					if (day < 10) {
						day = "0" + day;
					}
					var data = year + "-" + mouth + "-" + day;
					if (row.cgjhTime == data) {
						return 'color:red;';
					}
				}
			});
			
			//采购完成情况窗口
			$("#lfq-purchasePlan-wancqk").linkbutton({onClick:function(){
				var rows = $("#lfq-tb-purchasePlan").datagrid("getSelections");
				if (rows.length == 1) {
					if(rows[0].cgjhAuditstatus=="未审核"){
						$.messager.alert("提示", "该采购计划还未通过审核");
					}else{
						$('#lfq-purchasePlan-win-qingkuang').window('open');
						//初始化表格
						var cgjhNo = rows[0].cgjhNo;
						$("#lfq-dingdhao").html(cgjhNo);
						$("#lfq-tb-purchasedetails1").datagrid({
							url : 'selectHisPurchaseByCgjhNo',
							method : 'post',
							queryParams : {
								cgjhNo : cgjhNo
							}
						});
					}
				} else {
					$.messager.alert("提示", "只能选择一条记录，您目前选择了"
							+ rows.length + "条!");
				}
			}});
			
			//采购完成情况窗口加载数据完成时触发事件
			$("#lfq-tb-purchasedetails1").datagrid({onLoadSuccess:function(){
				var row = $("#lfq-tb-purchasedetails1").datagrid("getRows");
				if(row.length==0){
					$('#lfq-purchasePlan-win-qingkuang').window('close');
					$.messager.alert("提示", "该采购计划已全部购买完成");
				}
			}})
			
			//改变采购完成状态
			$("#lfq-btn-purchasePlanOk1").linkbutton({onClick:function(){
				var rows = $("#lfq-tb-purchasedetails1").datagrid("getSelections");
				if(rows.length>0){
					var arrs=[];
					for(var i=0;i<rows.length;i++){
						arrs.push(rows[i].cgNo);
					}
					$('<form>').form('submit', {
						url : 'updataPurchasedetailCgState',
						onSubmit : function(param) {
							param.arr = arrs;
						},
						success : function(data) {
							$.messager.alert("提示", "更改成功!");
							//多行删除表格的数据
							for(var i=0;i<rows.length;i++){		
								var inde = $("#lfq-tb-purchasedetails1").datagrid('getRowIndex',rows[i]);
								$('#lfq-tb-purchasedetails1').datagrid('deleteRow',inde);
							}
							var row = $("#lfq-tb-purchasedetails1").datagrid("getRows");
							if(row.length==0){
								$('#lfq-purchasePlan-win-qingkuang').window('close');
							}
						}
					});
				}else{
					$.messager.alert("提示", "请选择采购已完成的药品！");
				}
			}});
			
			//打开药品验收窗口
			$("#lfq-purchasePlan-yanshou").linkbutton({onClick:function(){
				$('#lfq-purchasePlan-win-yanshou').window({
					'title' : "药品验收",
					'href' : "LfqYanShouDrug"
				});
				$("#lfq-purchasePlan-win-yanshou").window("open");
			}});
			
			//打开药品入库窗口
			$("#lfq-purchasePlan-ruku").linkbutton({onClick:function(){
				$('#lfq-purchasePlanDrug-win-ruku').window({
					'title' : "药品入库",
					'href' : "LfqGrugRuku"
				});
				$("#lfq-purchasePlanDrug-win-ruku").window("open");
			}});
			
			//打开采购详情窗口
			$("#lfq-tb-purchasePlan").datagrid({onDblClickRow:function(rowIndex, rowData){
				$("#lfq-xqingCgNo").html(rowData.cgjhNo);
				$("#lfq-purchasePlan-win-caigouxqing").window("open");
				
				$("#lfq-tb-planCaigouxqing").datagrid({
					url : 'selectPurchasePlanCaiGouxq',
					method : 'post',
					queryParams : {
						cgjhNo : rowData.cgjhNo
					}
				});
			}});
			
		});
	</script>

	<table id="lfq-tb-purchasePlan" class="easyui-datagrid"
		data-options="
		    url:'selectPurchaseplanYaopAll',
			fitColumns:true,
			fit:true,
			nowrap:false,
			singleSelect:true,
			pagination: true,
			pageSize: 5,
			pageList: [5, 10, 15, 20],
			rownumbers: true,
			toolbar: '#lfq-tb5',
			border:false
			">
		<thead>
			<tr>
				<th data-options="field:'cgjhNo',width:'20%'">采购计划id</th>
				<th data-options="field:'name1',width:'12%'">创建人</th>
				<th data-options="field:'cgjhTime',width:'13%'">创建时间</th>
				<th data-options="field:'ckProducttype',width:'12%'">产品类型</th>
				<th data-options="field:'name2',width:'12%'">审核人</th>
				<th data-options="field:'cgjhAuditstatus',width:'12%'">审核状态</th>
				<th data-options="field:'cgjhAudittime',width:'13%'">审核时间</th>
		</thead>
	</table>

	<div id="lfq-tb5">
		<a id="lfq-purchasePlan-add1" class="easyui-linkbutton"
			data-options="iconCls:'icon-add',plain:true">制定采购计划</a> <a
			id="lfq-purchasePlan-add2" class="easyui-linkbutton"
			data-options="iconCls:'icon-addcg',plain:true">系统自制采购计划</a><a
			id="lfq-purchasePlan-wancqk" class="easyui-linkbutton"
			data-options="iconCls:'icon-caigouxq',plain:true">药品采购</a> <a
			id="lfq-purchasePlan-yanshou" class="easyui-linkbutton"
			data-options="iconCls:'icon-yanshou',plain:true">药品验收</a> <a
			id="lfq-purchasePlan-ruku" class="easyui-linkbutton"
			data-options="iconCls:'icon-ruku',plain:true">药品入库</a> <a
			id="lfq-purchasePlan-reload1" class="easyui-linkbutton"
			data-options="iconCls:'icon-reload',plain:true">刷新</a> <input
			id="lfq-purchasePlan-search1" class="easyui-searchbox"
			data-options="menu: '#lfq-mm2', width: 220, prompt: '请输入采购计划'" />
	</div>

	<div id="lfq-mm2" style="width: 120px">
		<div data-options="name:'计划编号'">计划编号</div>
	</div>

	<!-- 制定采购计划窗口 -->
	<div id="lfq-purchasePlan-win-add1" class="easyui-window"
		title="制定采购计划"
		data-options="collapsible:false,minimizable:false,maximizable:false,modal:true,iconCls:'icon-save',closed: true"
		style="width: 800px; height: 480px; padding: 5px;"></div>

	<!-- 系统制定采购计划窗口 -->
	<div id="lfq-xitongpurchasePlan-win-add2" class="easyui-window"
		title="制定采购计划"
		data-options="collapsible:false,minimizable:false,maximizable:false,modal:true,iconCls:'icon-save',closed: true"
		style="width: 800px; height: 450px; padding: 5px;"></div>
		
	<!-- 药品验收窗口 -->
	<div id="lfq-purchasePlan-win-yanshou" class="easyui-window"
		title="药品验收"
		data-options="collapsible:false,minimizable:false,maximizable:false,modal:true,iconCls:'icon-save',closed: true"
		style="width: 800px; height: 450px; padding: 5px;"></div>
	
	<!-- 药品入库窗口 -->
	<div id="lfq-purchasePlanDrug-win-ruku" class="easyui-window"
		title="药品入库"
		data-options="collapsible:false,minimizable:false,maximizable:false,modal:true,iconCls:'icon-save',closed: true"
		style="width: 800px; height: 450px; padding: 5px;"></div>

    <!-- 采购计划详情窗口 -->
	<div id="lfq-purchasePlan-win-caigouxqing" class="easyui-window"
		title="采购详情"
		data-options="collapsible:false,minimizable:false,maximizable:false,modal:true,iconCls:'icon-save',closed: true"
		style="width: 800px; height: 450px; padding: 5px;">		
		<div class="easyui-layout" data-options="fit:true">
		    <div data-options="region:'north',border:false" style="padding: 10px;">
		        <p style="text-align: center;font-size: 20px; padding: 0px;margin:0px;">采购编号<span style="color:red" id="lfq-xqingCgNo"></span>详情</p>
			</div>
			<div data-options="region:'center',border:false" style="padding: 10px;">
				<table id="lfq-tb-planCaigouxqing" class="easyui-datagrid"
					data-options="
						fitColumns:true,
						fit:true,
						nowrap:false,
						pagination: true,
						pageSize: 5,
						pageList: [5, 10, 15, 20],
						rownumbers: true,
						">
					<thead>
						<tr>
							<th data-options="field:'ypName',width:'14%'">药品名称</th>
							<th data-options="field:'ypType',width:'8%'">药品类型</th>
							<th data-options="field:'gysName',width:'16%'">供应商</th>
							<th data-options="field:'caigouNumber',width:'7%'">数量</th>
							<th data-options="field:'price',width:'6%'">价格</th>
							<th data-options="field:'danwei',width:'6%'">单位</th>
							<th data-options="field:'money',width:'10%'">总金额</th>
							<th data-options="field:'caigType',width:'8%'">采购状态</th>
							<th data-options="field:'yansType',width:'8%'">验收状态</th>
							<th data-options="field:'hegeNumber',width:'8%'">合格数量</th>
							<th data-options="field:'rukuType',width:'8%'">是否入库</th>
					</thead>
				</table>
			</div>
		</div>
	</div>
    
	<!-- 采购完成情况窗口 -->
	<div id="lfq-purchasePlan-win-qingkuang" class="easyui-window"
		title="采购完成情况"
		data-options="collapsible:false,minimizable:false,maximizable:false,modal:true,iconCls:'icon-save',closed: true"
		style="width: 800px; height: 450px; padding: 5px;">		
		<div class="easyui-layout" data-options="fit:true">
		    <div data-options="region:'north',border:false" style="padding: 10px;">
		        <p style="text-align: center;font-size: 20px; padding: 0px;margin:0px;">采购编号<span style="color:red" id="lfq-dingdhao"></span></p>
			</div>
			<div data-options="region:'center',border:false" style="padding: 10px;">
				<table id="lfq-tb-purchasedetails1" class="easyui-datagrid"
					data-options="
						fitColumns:true,
						fit:true,
						nowrap:false,
						pagination: true,
						pageSize: 5,
						pageList: [5, 10, 15, 20],
						rownumbers: true,
						">
					<thead>
						<tr>
							<th data-options="field:'cgNo',width:'10%',checkbox: true">采购id</th>
							<th data-options="field:'cpName',width:'20%'">产品名称</th>
							<th data-options="field:'ygsName',width:'20%'">供应商</th>
							<th data-options="field:'cgNumber',width:'8%'">数量</th>
							<th data-options="field:'cgUnit',width:'8%'">单位</th>
							<th data-options="field:'cgPrice',width:'8%'">价格</th>
							<th data-options="field:'cgState',width:'9%'">采购状态</th>
							<th data-options="field:'cgTotalprice',width:'9%'">总价格</th>
							<th data-options="field:'cgBatchnumber',width:'12%'">批文编号</th>
					</thead>
				</table>
			</div>
			<div data-options="region:'south',border:false"
				style="text-align: right; padding: 5px 0 0;">
				<a id="lfq-btn-purchasePlanOk1" class="easyui-linkbutton"
					data-options="iconCls:'icon-ok', plain:true">确定采购完成</a> <a
					class="easyui-linkbutton"
					data-options="iconCls:'icon-cancel', plain:true"
					href="javascript:$('#lfq-purchasePlan-win-qingkuang').window('close');"
					onclick="">取消</a>
			</div>
		</div>
	</div>
</body>
</html>